package com.dxt.rabbitmq.service.ack;

import com.dxt.rabbitmq.config.ConsumerAckConfig;
import com.dxt.rabbitmq.vo.TestMessage;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class AckConsumer {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @RabbitListener(queues = ConsumerAckConfig.QUEUE)
    public void consume(TestMessage testMessage, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
        //做消费处理逻辑
        channel.basicNack(tag, false, false);
//        channel.basicAck(tag, true);
        System.out.println("AckConsumer consume msg: " + testMessage.toString());
    }
}
